package com.buka.communicate.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.buka.communicate.R;
import com.buka.communicate.entity.User;
import com.buka.communicate.entity.WorkTag;

import net.neiquan.applibrary.base.MyBaseAdapter;
import net.neiquan.applibrary.utils.PixelUtil;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * 作者 ： dyj
 * 时间 ： 2016/12/29.
 */

public class WorkTagAdapter extends MyBaseAdapter<WorkTag, WorkTagAdapter.ViewHolder> {

    public WorkTagAdapter(Activity context, List data) {
        super(context, data);
    }

    @Override
    protected ViewHolder getViewHolder() {
        return new ViewHolder(mInflater.inflate(R.layout.item_work_tag, null));
    }

    @Override
    protected void onBindViewHolder_(ViewHolder holder, int position) {
        if (data != null && data.size() > 0) {
            WorkTag workTag = data.get(position);
            if(position==0){
                holder.mRootLL.setPadding(PixelUtil.dp2px(context,20),PixelUtil.dp2px(context,30),PixelUtil.dp2px(context,20),PixelUtil.dp2px(context,10));
            }
            holder.titleTv.setVisibility(TextUtils.equals("其他",workTag.getTitle()) ? View.INVISIBLE : View.VISIBLE);
            holder.titleTv.setBackground(context.getResources().getDrawable(workTag.getBgDrawable()));
            holder.titleTv.setText(workTag.getTitle());
            holder.contentTv.setText(workTag.getContent());
            holder.chosenLogo.setVisibility(workTag.isChosen() ? View.VISIBLE : View.GONE);
        }
    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.titleTv)
        TextView titleTv;
        @InjectView(R.id.contentTv)
        TextView contentTv;
        @InjectView(R.id.chosenLogo)
        ImageView chosenLogo;
        @InjectView(R.id.mRootLL)
        LinearLayout mRootLL;

        ViewHolder(View view) {
            super(view);
            ButterKnife.inject(this, view);
        }
    }
}
